import React from 'react';
import { Icon } from 'antd-mobile';
import { connect } from 'dva';
import { routerRedux } from 'dva/router';
import styles from './common.css';
import content from '../../common/contentCss/content.css';
import CustTitle from '../../common/title/title';
import CustList from '../../../../common/lists/CustomList';
import Screen from '../../../../common/plugin/screen/screen';

const tempItem = {}

function Index({ dispatch, loading, categoryNavPartTime, relations}) {

  const { typeArr, areasArr} = relations;
  const {pageNum,pages,pageSize,isShow,ordey,hiddenArr,
    ordeyIndex,areaIndex,typeNameIndex,selectIndex, itemData } = categoryNavPartTime;

  const categoryNavPartTimeProps = {
    list:[tempItem],
    onViewMember(id){
      console.log('id', id);

    },
    showLimit(id){
      console.log('id', id);
    },
    onPagination() {
      // console.log('loading',loading);
      // console.log('pageNum',pageNum);
      // console.log('pages',pages);
      if (loading || JSON.stringify(list) == "[]") {
        return;
      }

      if (parseInt(pageNum) >= parseInt(pages)) {
        return;
      }
      dispatch({
        type: 'partTime/query',
        payload: {
          pageNum: pageNum + 1,
        }
      })
    }
  };

  const titleProps = {
    titleName: itemData.label,
    goBack(){
      dispatch(routerRedux.goBack());
    },
  }

  const showScreen = () => {

    let showScreenStyles = [`${styles.screen}`];
    if(isShow != -1){
      showScreenStyles.push(`${styles.showScreenList}`)
    }

    const screenProps = {
      isShow,
      ordeyIndex,
      areaIndex,
      typeNameIndex,
      hiddenArr,
      selectIndex,
      list:[],
      ordey,
      areasArr,
      typeArr,
      onClickF(id){
        let number=-1
        if ( id==isShow ) {
          number=-1
        } else if (id==1) {
          number = 1
        } else if (id==2) {
          number = 2
        } else {
          number = 3
        }
        dispatch({
          type: 'categoryNavPartTime/querySuccess',
          payload: {
            isShow: number,
          }
        })
      },
      onSelect(id, index, itemData){
        if (id==1) {
          // console.log('综合', JSON.stringify(itemData));
          dispatch({
            type: 'categoryNavPartTime/querySuccess',
            payload: {
              isShow: -1,
              selectIndex:1,
              ordeyIndex: index,
              key:itemData.value,
            }
          });
          dispatch({
            type: 'categoryNavPartTime/query',
            payload: {
            }
          })

        } else if (id==2) {
          // console.log('区域', JSON.stringify(itemData));
            dispatch({
              type: 'categoryNavPartTime/querySuccess',
              payload: {
                isShow: -1,
                selectIndex:2,
                areaIndex:index,
                district:itemData.name
              }
            })
            dispatch({
              type: 'categoryNavPartTime/query',
              payload: {
              }
            })
        } else if (id==3) {
          console.log('类型', JSON.stringify(itemData));
            dispatch({
              type: 'categoryNavPartTime/querySuccess',
              payload: {
                isShow: -1,
                selectIndex:3,
                typeNameIndex: index,
                typeId:itemData.id
              }
            })
            dispatch({
              type: 'categoryNavPartTime/query',
              payload: {
              }
            })
        }
      },

    }

    return (
      <div className={showScreenStyles.join(' ')}>
        <Screen {...screenProps} />
      </div>
    )
  }

  return(
    <div className={content.content}>
      <CustTitle {...titleProps}/>
      {showScreen()}
      <div className={styles.jobList}>
        <CustList {...categoryNavPartTimeProps}/>
      </div>

    </div>
  )
}

function mapStateToProps(state, ownProps) {
  return {
    loading: state.loading.global,
    categoryNavPartTime: state.categoryNavPartTime,
    relations: state.relations,
  }
}

export default connect(mapStateToProps)(Index);
